<div class="layui-fluid nepadmin-pad0 nepadmin-mar0 list0 notice" id="advert_list" lay-title="广告管理">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card hxr-layui-card" id="userlistv">
                    <div class="layui-form layui-card-header hxradmin-card-header">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">关键词查询</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="user" placeholder="公告标题" class="layui-input" autocomplete="off">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn" data-type="reload" id="drawingssearch">搜索</button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-card-body">
                        <div>
                            <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
                            <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
                        </div>
                        <table class="layui-hide" id="list-table" lay-filter="list-table"></table>
                    </div>
                    <script type="text/html" id="list-tableF">
                        <input type="checkbox" name="status" lay-skin="switch" lay-text="是|否" lay-filter="list-tableF"
                               value="{{ d.status }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.status == '1' ? 'checked' : '' }}>
                    </script>
                    <div id="list-toolbar" style="display: none;">
                        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<style type="text/css">
    .layui-laydate-content td.laydate-selected {
        background: #dbe3f5;
    }

    .layui-laydate td.layui-this {
        background: #a4bfff !important;
    }
</style>
<script>
    var formurl = 'system/noticeform',
        formarea = ['700px', '600px'];
    //表格数据渲染

    layui.use(['table', 'form'], function() {
        var table = layui.table,
            form = layui.form,
            $ = layui.$,
            laydate = layui.laydate;
        layui.admin.initlist(table, 'advert/list', 275, [
            [{
                type: 'checkbox',
                fixed: 'left'
            }, {
                field: 'advert_id',
                title: 'ID',
                width: 50
            }, {
                field: 'advert_name',
                title: '公司',
                width: 200
            }, {
                field: 'advert_money',
                title: '费用',
                minWidth: 200
            }, {
                field: 'time_type',
                title: '时间',
                width: 150
            }, {
                field: 'create_time',
                title: '创建时间',
                width: 200
            }, {
                field: 'status',
                title: '是否启用',
                width: 100,
                templet:'#list-tableF'
            }, {
                title: '操作',
                toolbar: '#list-toolbar',
                width: 150,
                fixed: 'right'
            }]
        ])
        //监听表格表单操作
        form.on('switch(list-tableF)', function(obj){
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);
            layui.admin.ajax('advert/update',{
                status:json.status==1?2:1,
                notice_id:json.notice_id
            }).then(function(res){
                table.reload('list-table');
            }).catch(function(res){});
        });
        //监听表格操作事件
        table.on('tool(list-table)', function(obj) {
            var data = obj.data;
            //删除
            if (obj.event === 'del') {
                layer.confirm('确定删除' + data.title + '?', function(index) {
                    layui.admin.delF(table, 'advert/delete', {
                        notice_id: data.notice_id
                    });
                });
            } else if (obj.event === 'edit') { //编辑
                layui.admin.pupF('编辑公告', formarea, formurl, 2, data)
            }
        });
        var active = {
            //多行删除
            batchdel: function() {
                layui.admin.delsF(table, 'advert/delete', 'notice_id');
            }
            //添加
            ,
            add: function(othis) {
                layui.admin.pupF('添加公告', formarea, formurl, 1, {})
            }
        };
        //操作dom
        $('.layui-btn.layuiadmin-btn-list').on('click', function() {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //搜索
        $('#drawingssearch').on('click', function() {
            var obj = $(this).parents('.layui-form-item');
            var val1 = obj.find('input[name="user"]'),
                val2 = obj.find('input[name="role"]'),
                val3 = obj.find('input[name="status"]');
            //执行重载

            table.reload('list-table', {
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: {
                    search_text: val1.val(),
                    role_id: val2.attr('data'),
                    admin_status: val3.attr('data')
                }
            });
        });
    });
</script>
